package com.tezign.intelligence.mini.dam.aifamilyconsultant.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tezign.intelligence.mini.dam.aifamilyconsultant.bean.ResponseBean;
import com.tezign.intelligence.mini.dam.aifamilyconsultant.bean.VoiceConfigResp;
import com.tezign.intelligence.mini.dam.aifamilyconsultant.constant.Constant;
import com.tezign.intelligence.mini.dam.aifamilyconsultant.util.SmartVoiceUtil;
import io.github.cdimascio.dotenv.Dotenv;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.tezign.intelligence.mini.dam.aifamilyconsultant.constant.Constant.ALIYUN_AK_ID;
import static com.tezign.intelligence.mini.dam.aifamilyconsultant.constant.Constant.VOICE_APPKEY;

/**
 * todo
 *
 * @Author ouyangkang
 * @date 2025/2/24
 */

@Api(tags = "智能语音交互管理")
@Slf4j
@CrossOrigin("*")
@RestController
@RequiredArgsConstructor
@RequestMapping(Constant.APPLICATION_NAME + "/voice")
public class VoiceController {
	private final SmartVoiceUtil smartVoiceUtil;


	@ApiOperation(value = "获取语音配置")
	@GetMapping("/config")
	public ResponseBean<VoiceConfigResp> getConfig() {
		VoiceConfigResp voiceConfigResp = new VoiceConfigResp();
		try {
			String token = smartVoiceUtil.getToken();
			voiceConfigResp.setToken(token);

		} catch (ClientException e) {
			throw new RuntimeException(e);
		}
		Dotenv dotenv = Dotenv.load();
		String appKey = dotenv.get(VOICE_APPKEY);
		voiceConfigResp.setAppKey(appKey);
		return new ResponseBean<VoiceConfigResp>().success(voiceConfigResp);
	}
}
